package vue;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComboBox;
import javax.swing.JDialog;

import lib.EnsembleListe;
import lib.EnsembleListePerso;
import lib.EnsembleTableau;
import vue.composants.Boutton;

public class NouvelEnsembleDialog extends JDialog implements ActionListener{

	private FenetrePrincipale mere;
	private Boutton bouttonAjout;
	private JComboBox TypeDisponibleCombo;
	
	public NouvelEnsembleDialog(FenetrePrincipale mere)
	{
		super(mere);
		//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setBounds(500, 500, 500, 500);
		
		this.bouttonAjout = new Boutton("Ajouter");
		this.bouttonAjout.addActionListener(this);		
		
		String[] param = new String[] {"Liste","Tableau","File"};
		this.TypeDisponibleCombo= new JComboBox(param);
		
		this.getContentPane().setLayout(new GridLayout());
		this.getContentPane().add(this.TypeDisponibleCombo);
		this.getContentPane().add(this.bouttonAjout);
		
		this.setMere(mere);
		
		this.pack();
		this.setVisible(true);
	}

	/**
	 * @return the mere
	 */
	public FenetrePrincipale getMere() {
		return mere;
	}

	/**
	 * @param mere the mere to set
	 */
	public void setMere(FenetrePrincipale mere) {
		this.mere = mere;
	}
	
	private void ajouteEnsemble()
	{
		String type = (String) this.TypeDisponibleCombo.getSelectedItem();
		
			if(type=="Liste") this.getMere().getMesEnsemble().add(new EnsembleListe());
			if(type=="Tableau" ) this.getMere().getMesEnsemble().add(new EnsembleTableau());
			if(type=="File" ) this.getMere().getMesEnsemble().add(new EnsembleListePerso());
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==this.bouttonAjout)
		{
			this.ajouteEnsemble();
		}
	}
}
